<%--
  Created by IntelliJ IDEA.
  User: 18009118265
  Date: 2020/9/15
  Time: 15:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>Title</title>
    <link type="text/css" href="${pageContext.request.contextPath}/static/layui/css/layui.css" rel="stylesheet"/>

    <link type="text/css" rel="stylesheet"
          href="${pageContext.request.contextPath}/static/css/bootstrap.min.css">
</head>
<body>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/static/js/jquery-3.4.1.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/bootstrap.min.js"></script>
<%=request.getContextPath()%><br>
<div class="demoTable">
    状态：
    <div class="layui-inline">
        <input class="layui-input" name="state" id="demoReload2" autocomplete="off">
    </div>
    <button class="layui-btn" data-type="reload">搜索</button>
</div>
<div id="modleBox" style="display: none; margin: auto">
    <form action="/recruitpost/insert" method="post">
        id:<input type="text" name="rpid"><br>
        招聘者id:<input type="text" name="rid"><br>
        职位名称:<input type="text" name="post"><br>
        职位类型:<input type="text" name="posttype"><br>
        薪资:<input type="text" name="salary"><br>
        经验:<input type="text" name="experience"><br>
        学历:<input type="text" name="education"><br>
        职位关键字:<input type="text" name="rpkey"><br>
        职位详情:<input type="text" name="details"><br>
        <fieldset class="layui-elem-field site-demo-button" style="margin: auto; border: solid 0px">
            <div style="margin-left: 160px">
                <button type="submit" class="layui-btn layui-btn-normal">提交</button>
            </div>
        </fieldset>
    </form>
</div>


<table class="layui-hide" id="share" lay-filter="share"></table>
<script src="${pageContext.request.contextPath}/static/layui/layui.all.js" charset="utf-8"></script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
</script>
<script type="text/html" id="btnDemo">
    <a class="layui-btn layui-btn-xs" lay-event="add">添加</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
</script>
<script>

    function findAll() {
        var table = layui.table;
        //方法级渲染
        table.render({
            elem: '#share'
            , url: '/recruitpost/test'//就是他
            , toolbar: '#btnDemo'//开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                , layEvent: 'LAYTABLE_TIPS'
                , icon: 'layui-icon-tips'
            }]
            , title: '招聘职位表'
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'rpid', title: 'ID', width: 80,fixed: 'left', unresize: true, sort: true}
                , {field: 'rid', title: '招聘者id', width: 120,edit: 'text'}
                , {field: 'post', title: '职位名称', width: 120,edit: 'text'}
                , {field: 'posttype', title: '职位类型', width: 120,edit: 'text'}
                , {field: 'salary', title: '薪资', width: 120,edit: 'text'}
                , {field: 'experience', title: '经验', width: 120,edit: 'text'}
                , {field: 'education', title: '学历', width: 120,edit: 'text'}
                , {field: 'rpkey', title: '职位关键字', width: 120,edit: 'text'}
                , {field: 'details', title: '职位详情', width: 120,edit: 'text'}
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150}
            ]]
            , page: true
        });
    }

    layui.use('table', function () {
        var table = layui.table;
        //方法级渲染
        table.render({
            elem: '#share'
            , url: '/recruitpost/test'//就是他
            , toolbar: '#btnDemo'//开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                , layEvent: 'LAYTABLE_TIPS'
                , icon: 'layui-icon-tips'
            }]
            , title: '招聘职位表'
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'rpid', title: 'ID', width: 80,fixed: 'left', unresize: true, sort: true}
                , {field: 'rid', title: '招聘者id', width: 120,edit: 'text'}
                , {field: 'post', title: '职位名称', width: 120,edit: 'text'}
                , {field: 'posttype', title: '职位类型', width: 120,edit: 'text'}
                , {field: 'salary', title: '薪资', width: 120,edit: 'text'}
                , {field: 'experience', title: '经验', width: 120,edit: 'text'}
                , {field: 'education', title: '学历', width: 120,edit: 'text'}
                , {field: 'rpkey', title: '职位关键字', width: 120,edit: 'text'}
                , {field: 'details', title: '职位详情', width: 120,edit: 'text'}
                , {field: 'right', title: '操作', width: 200, align: 'center', toolbar: '#barDemo'}
            ]]
            , page: true
        });

        //监听工具条
        table.on('tool(share)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                alert(data.rpid);
                $.ajax({
                    type: "get",
                    url: "/recruitpost/update",
                    data: {
                        rpid: data.rpid,
                        rid: data.rid,
                        post: data.post,
                        posttype: data.posttype,
                        salary: data.salary,
                        experience:data.experience,
                        education: data.education,
                        rpkey: data.rpkey,
                        details: data.details,
                    },
                    success: function (mess) {
                        alert(mess);
                    }
                });
            }
        });


        var $ = layui.$, active = {
            reload: function () {
                var demoReload1 = $('#demoReload1');
                var demoReload2 = $('#demoReload2');
                //执行重载
                table.reload('testReload', {
                    url: '/recruitpost/test',
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        nickname: demoReload1.val(),
                        state: demoReload2.val()
                    }
                }, 'data');
            }
        };
        //监听头工具栏事件
        table.on('toolbar(share)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id)
                , data = checkStatus.data; //获取选中的数据
            if (obj.event === 'del') {
                var idArry = "idArry=" + data[0].rpid;
                for (var i = 1; i < data.length; i++) {
                    idArry += "," + data[i].rpid;
                }
                $.ajax({
                    type: "get",
                    url: "/recruitpost/delete",
                    data: idArry,
                    success: function (mess) {
                        // alert(mess);
                        // window.location = mess;
                        findAll();
                    }

                });
            } else if (obj.event === 'add') {
                layui.use(['layer'], function () {
                    var layer = layui.layer, $ = layui.$;
                    layer.open({
                        type: 1
                        , area: ['400PX', '300PX']
                        , content: $('#modleBox')
                        , btnAlign: 'c' //按钮居中
                        , shade: 0 //不显示遮罩
                        , zIndex: layer.zIndex
                        , yes: function () {
                            layer.closeAll();
                        }
                    });

                });
            }
        });

    });
</script>
</body>
</html>

